import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'dart:async';

import 'package:flutter_app_05/widget/bottom_navigation_widget.dart';

import 'indicator.dart';

class ViewPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _ViewPageState();

}

class _ViewPageState extends State<ViewPage> {
  final PageController controller = PageController(initialPage: 0);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView(
        scrollDirection: Axis.horizontal,
        reverse: false,
        controller: controller,
        // controller: PageController(
        //   initialPage: 0,
        //   viewportFraction: 1,
        //   keepPage: true,
        // ),
        physics:BouncingScrollPhysics(),
        pageSnapping: true,
        onPageChanged: (index) {
          //监听事件

          print('index=====$index');
        },
        children: <Widget>[
          Container(
            padding: EdgeInsets.fromLTRB(0, 50, 0, 50),
            color: Colors.blue,
            child: Center(
              child: new Image(
                image: new AssetImage("images/close.png"),
                width: 25,
                height: 25,
              ),
            ),
          ),
          Container(
            color: Colors.greenAccent,
            child: Center(
              child: Text(
                '第2页',
                style: TextStyle(color: Colors.black, fontSize: 20.0),
              ),
            ),
          ),
          Container(
            color: Colors.deepOrange,
            child: Center(
              child: Text(
                '第3页',
                style: TextStyle(color: Colors.black, fontSize: 20.0),
              ),
            ),
          ),
          Container(
            color: Colors.greenAccent,
            child: Center(
              child: Text(
                '第4页',
                style: TextStyle(color: Colors.black, fontSize: 20.0),
              ),
            ),
          ),
          Container(
            decoration: new BoxDecoration(
            image: new DecorationImage(
            image: new AssetImage("images/close.png"),
            //这里是从assets静态文件中获取的，也可以new NetworkImage(）从网络上获取
            // centerSlice: new Rect.fromLTRB(270.0, 180.0, 1360.0, 730.0),
            ),
            ),
            alignment: Alignment.center,
            child: Center(
              child: FlatButton(
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.all(Radius.circular(80.0)),
                ),
                child: Text(
                  '进入',
                  style: TextStyle(color: Colors.white,fontSize: 15),
                ),
                color: Colors.green,
                onPressed: () {
                  Navigator.of(context).push(
                      MaterialPageRoute(builder: (context)=>BottomNavigationWidget())
                  );
                },
              ),

            ),
          ),
                Indicator(
                  controller: controller,
                  itemCount: 5,
                ),
        ],
      ),
    );
  }
}